#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 300010;
int n, m;
int s[N], q[N];
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];
        s[i] += s[i - 1];
    }
    int hh = 0, tt = -1, res = -0x3f3f3f3f;
    for (int i = 0; i <= n; i++)
    {
        if (hh <= tt && q[hh] < i - m) hh++;
        if (i) res = max(res, s[i] - s[q[hh]]);
        while (hh <= tt && s[q[tt]] >= s[i]) tt--;
        q[++tt] = i;
    }
    cout << res << endl;
    return 0;
}